﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Station.Inspect
{
    public class GlobalHotKey
    {
        // 热键消息
        private const int WM_HOTKEY = 0x0312;

        // 热键ID
        private static int _hotKeyID = 1123;
        // 定义热键ID
        public enum Hotkeys
        {
            Hotkey1 = 1000,
            Hotkey2 = 1001,
            Hotkey3 = 1002,
            Hotkey4 = 1003,
            Hotkey5 = 1004,
            Hotkey6 = 1005,
            Hotkey7 = 1006,
            // 更多热键...
        }

        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);

        [DllImport("user32.dll", SetLastError = true)]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        // 热键修饰键
        [Flags()]
        public enum KeyModifiers
        {
            None = 0,
            Alt = 1,
            Control = 2,
            Shift = 4,
            Windows = 8
        }

        public GlobalHotKey(IntPtr hWnd, int _hotKeyID, KeyModifiers modifiers, Keys key)
        {
            RegisterHotKey(hWnd, _hotKeyID, modifiers, key);
        }

        ~GlobalHotKey()
        {
            UnregisterHotKey(IntPtr.Zero, _hotKeyID);
        }

        public static void OnHotKeyPressed(Message m)
        {
            if (m.Msg == WM_HOTKEY)
            {
                // 处理热键事件
                // Console.WriteLine("热键被按下");
            }
        }
    }
}
